import json
import pandas as pd
import os

# 文件路径
json_file_path = 'c:\\Users\\asyf\\Desktop\\反馈json.txt'
excel_file_path = 'c:\\Users\\asyf\\Desktop\\反馈数据.xlsx'

print(f"读取JSON文件: {json_file_path}")

try:
    # 读取JSON文件（使用utf-8-sig编码处理BOM）
    with open(json_file_path, 'r', encoding='utf-8-sig') as f:
        data = json.load(f)

    print(f"成功读取JSON文件，共有 {len(data)} 条记录")

    # 转换为DataFrame
    df = pd.DataFrame(data)

    # 导出到Excel
    df.to_excel(excel_file_path, index=False, engine='openpyxl')

    print(f"数据已成功导出到Excel: {excel_file_path}")
    print(f"Excel文件大小: {os.path.getsize(excel_file_path) / 1024:.2f} KB")

except Exception as e:
    print(f"处理文件时出错: {e}")
    import traceback

    traceback.print_exc()